package com.cssl.controller;

import cn.hutool.core.util.ObjectUtil;
import com.cssl.domain.dto.DtsBrandDto;
import com.cssl.service.DtsBrandService;
import com.cssl.util.InfoCode;
import com.cssl.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/brand")
public class DtsbrandController {

    @Autowired
    DtsBrandService dtsBrandService;
    @PostMapping("/list")
    Result dtsissuelist(@RequestBody DtsBrandDto dtsBrandDto){
        Map brandlist=dtsBrandService.findPagebrand(dtsBrandDto);
        if (brandlist==null|| ObjectUtil.isEmpty(brandlist.get("list"))) {
            return Result.result(InfoCode.QUERY_EMPTY, InfoCode.MESSAGE_QUERY_EMPTY, null, System.currentTimeMillis());
        }
        System.out.println("订单数据"+dtsBrandDto.getLimit()+dtsBrandDto.getPage());
        System.out.println("订单状态"+dtsBrandDto);
        return Result.result(InfoCode.OK,InfoCode.MESSAGE_OK,brandlist,System.currentTimeMillis());
    }

    @DeleteMapping("/delete")
    Result dtsbranddelete(@RequestParam("ids") String ids){
        boolean branddelete=dtsBrandService.branddelete(ids);
        if(branddelete){
            return Result.result(InfoCode.OK, "删除成功", null, System.currentTimeMillis());
        }else {
            return Result.result(InfoCode.FAILED, "删除失败", null, System.currentTimeMillis());
        }
    }
    @PostMapping("/updatebrand")
    Result updatebrand(@RequestBody Map updatebrand){
        int brandadd=dtsBrandService.updatebrand(updatebrand);
        System.out.println("信息"+updatebrand.size());
        return Result.result(InfoCode.OK,InfoCode.MESSAGE_OK,brandadd,System.currentTimeMillis());
    }
    @PostMapping("/addbrand")
    Result addbrand(@RequestBody Map addbrand){
        int brandadd=dtsBrandService.addbrand(addbrand);
        System.out.println("信息"+addbrand.size());
        return Result.result(InfoCode.OK,InfoCode.MESSAGE_OK,brandadd,System.currentTimeMillis());
    }


}
